/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-08-31
 * Time: 18:37
 */
public class test_4 {
    // 1. 创建 dp 表
    // 2. 初始化
    // 3. 填表
    // 4. 返回值
    public int maxTurbulenceSize(int[] arr) {
        int n = arr.length;
        int[] f = new int[n];
        int[] g = new int[n];
        for (int i = 0; i < n; i++) {
            f[i] = g[i] = 1;
        }
        int ret = 1;
        for (int i = 1; i < n; i++) {
            if (arr[i - 1] < arr[i]) {
                f[i] = g[i - 1] + 1;
            } else if (arr[i - 1] > arr[i]) {
                g[i] = f[i - 1] + 1;
            }
            ret = Math.max(ret, Math.max(f[i], g[i]));
        }
        return ret;
    }
}
